/***************************************************************************
创建者：朱志平
 开始时间：               : 2016.12.02
 copyright            : (C) 同川科技
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   更新程序、恢复出厂设置视窗
*                                                                         *
 ***************************************************************************/
#include "updateprogramview.h"
#include "ui_updateprogramview.h"


UpdateProgramView::UpdateProgramView(QWidget *parent):
        QWidget(parent),
        ui(new Ui::UpdateProgramView)
{
    ui->setupUi(this);

    ui->browseHmi_Btn->setText(tr("浏览"));
    ui->updateHmi_Btn->setText(tr("开始更新"));
    ui->browseCont_Btn->setText(tr("浏览"));
    ui->updateCont_Btn->setText(tr("开始更新"));
    ui->restoreHmi_Btn->setText(tr("示教器程序恢复出厂状态"));
    ui->restoreController_Btn->setText(tr("控制器程序恢复出厂状态"));
}

void UpdateProgramView::updateView()
{
    ui->hmiPro_lineEdit->setText(hmiProgram);
    ui->controllerPro_lineEdit->setText(controllerProgram);
}

void UpdateProgramView::returnMessage(QString message)
{
    QMessageBox::information(this, tr("更新程序"), message);
}

void UpdateProgramView::on_browseHmi_Btn_clicked()
{
    QString filePath;
    QFileInfo fileInfo;
    filePath = QFileDialog::getOpenFileName(this, tr(""), uDiskLocation , tr(""));
    fileInfo = QFileInfo(filePath);

    hmiProgram = fileInfo.fileName();

    updateView();
}

void UpdateProgramView::on_browseCont_Btn_clicked()
{
    QString filePath;
    QFileInfo fileInfo;
    filePath = QFileDialog::getOpenFileName(this, tr(""), uDiskLocation , tr(""));
    fileInfo = QFileInfo(filePath);

    controllerProgram = fileInfo.fileName();

    updateView();
}

void UpdateProgramView::on_updateHmi_Btn_clicked()
{
    emit updateHmiProgram(hmiProgram);
}

void UpdateProgramView::on_updateCont_Btn_clicked()
{
    emit updateControllerProgram(controllerProgram);
}

void UpdateProgramView::on_restoreHmi_Btn_clicked()
{
    emit restoreHmiFactoryProgram();
}

void UpdateProgramView::on_restoreController_Btn_clicked()
{
    emit restoreControllerFactoryProgram();
}
